



var userlist = (function (){

	var init = function(){
	    // getUserInfo();
	    $("#imgupload").on("click",function(){

        });

         $("#imgupload").change(function () {
             debugger;

            var $this = $(this);
             var file = this.files[0];

             var fd = new FormData(document.getElementById("uploadForm"));
             fd.append('file', file);
             console.log(fd);
             $.ajax({
                 // url: Think.APP+'/Usercenter/upload_img_header',
                 url: Think.APP+'/Usercenter/upload_img_header',
                 type: 'post',
                 data: fd,
                 processData: false,  // 告诉jQuery不要去处理发送的数据
                 contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
                 success: function(data) {
                     if(data){
                         debugger;
                         $("#face").val(data.thumb_url);
                          $('#imguploadurl').attr('src',Think.PUBLIC+data.thumb_url);
                     }
              },
              error:function(){

              }
            })
           return  false;
        })

        $("#user_photo img").on("click",function(){
            $("#imgupload").trigger("click");
        })
        var postUrl= Think.APP+'/Public/check_user_is_existence';
        var dataInfo = {username:function(){ return $("#name").val()}};
        var remoteInfo = GetRemoteInfo(postUrl, dataInfo);
        var pwdStr = {pwd:function(){return $("#pwd").val()}};
        var postUrlPwd = Think.APP+'/Usercenter/is_pwd_true';
        var remotoPwd = GetRemoteInfo(postUrlPwd,pwdStr);
        var options = {
            rules: {
                username:{
                    required: true,
                    remote:remoteInfo
                },

                pwd:{
                    maxlength:16,
                    minlength:5,
                    remote:remotoPwd
                },
                repwd:{
                    maxlength:16,
                    minlength:5
                },
                erepwd: {
                    equalTo:"#repwd"
                }
            },
            messages: {
                username:{
                    required:"请输入用户昵称",
                    remote:"用户名已存在"
                },

                pwd:{

                    maxlength:"请输入16个以内的字符",
                    minlength:"请输入5个以上的字符",
                    remote:"密码错误"
                },
                repwd:{

                    maxlength:"请输入16个以内的字符",
                    minlength:"请输入5个以上的字符"
                },
                erepwd:{
                    equalTo:"两次密码不一致"
                }
            },
        };
        var val = $("#userlistform").validate(options);
	    debugger;
        $("#submitBtn").on("click",function(e){
            e.preventDefault();
            if(val.form()){
                var formJson = $("#userlistform").serializeObject();
                if(formJson['pwd'] !== ''){
                    for(var k in formJson){
                        if(k==="repwd"){
                            formJson["pwd"] = formJson["repwd"]
                            delete formJson[k];
                            delete formJson["erepwd"];
                        }
                    }
                }
                debugger;
                $.ajax({
                    url:Think.APP+"/Usercenter/save_user_list",
                    type:"post",
                    data:formJson,
                    dataType:"json",
                    success:function(data){
                        // data = JSON.stringify(data);
                        // alert(data);
                        if(data.status==1){
                            history.go(0);
                        }
                    },
                    error:function(xhr){
                        alert("service closed")
                    }
                })



            }


        })
//         $("form#userlistform").submit(function(e) {
//             e.preventDefault();
//
// //             return false;
//
//         });
        // $("").off("click").on("click",function(){
        //
        //     console.log($("#userlistform").serialize());
        //
        //
        //
        // })

	};

    // function getUserInfo(){
    //     $.ajax({
    //         url:Think.APP+"/Usercenter/get_user_list",
    //         type:"get",
    //         dataType:"json",
    //         success:function(data){
    //             debugger;
    //             var rowInfo = data.row;
    //             $("#name").val(rowInfo.name);
    //             $("#describe").val(rowInfo.describe);
    //             $("#imguploadurl").attr("src",Think.PUBLIC+rowInfo.face);

    //         },
    //         error:function(xhr){
    //             console.log("service closed")
    //         }
    //     })

    // }



	return {
		Init:init

	}






})();
